package com.etc.service;

import com.etc.dao.EngageDao;
import com.etc.entity.Engage;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.jsp.tagext.PageData;
import java.util.List;

@Service
public class EngageServiceImpl implements EngageService{
    //调用持久层
    @Autowired
    EngageDao dao;

    /**
     * 增加订单
     * @param engage
     * @return
     */
    @Override
    public boolean addEngage(Engage engage) {
        return dao.addEngage(engage);
    }

    /**
     * 根据房间类型编号删除订单
     * @param rtid
     * @return
     */
    @Override
    public boolean delEngage(String rtid) {
        return dao.delEngage(rtid);
    }

    @Override
    public List<Engage> getAllEngage() {
        Object roomNum = new Object();
        Object engageStatus = new Object();
        return dao.queryAllEngage(roomNum,engageStatus);
    }

    /**
     * 修改支付状态
     * @param userid
     * @param status
     * @param chkno
     * @return
     */
    @Override
    public boolean getEditStatusEngageList(Integer userid, Integer status, Integer chkno) {
        return dao.editStatusEngageList(userid,status,chkno);
    }

    /**
     * 分页
     * @param spc
     * @param kd
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageInfo<Engage> findByKeyForEn(String spc, String kd, int pageNum, int pageSize) {
        //1.开始分页
        PageHelper.startPage(pageNum, pageSize);
        //2.执行查询所有订单信息
        int engageStatus = (int) new Object();
        Object roomNum = new Object();
        List<Engage> list = dao.queryAllEngage(pageNum,pageSize, (Integer) roomNum,engageStatus);
        //3.通过pageInfo进行包装,PageInfo包含了非常丰富的分页属性
        PageInfo<Engage> pageInfo = new PageInfo<Engage>(list);
        return pageInfo;
    }

    @Override
    public PageData pageStatus(Integer pageNo, Integer pageSize, Integer userid, Integer status) {
        return (PageData) dao.statuschknoList(pageNo,pageSize,userid,status);
    }

    @Override
    public int modifyEngage(Engage engage) {
        return dao.modifyEngage(engage);
    }

    @Override
    public List<Engage> getAllEngage(int pageNum, int pageSize, int roomNum, int engageStatus) {
        return dao.queryAllEngage(pageNum,pageSize,roomNum,engageStatus);
    }

    @Override
    public List<Engage> queryEngageByUserId(String userId) {
        return dao.queryEngageByUserId(userId);
    }

    @Override
    public int updateUserEngage(String userId) {
        return dao.updateUserEngage(userId);
    }

    @Override
    public boolean userAddEngage(String userId, String rtId, Integer roomNum, String begin, String end) {
        int n = dao.userAddEngage(userId, rtId, roomNum, begin, end);
        return n>0;
    }
}
